Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
base is the foundation for creating modular, unit testable and highly pluggable node.js applications, starting with a handful of common methods, like `set`, `get`, `del` and `use`.
The 'base' npm package is a framework for rapidly building high-quality node.js applications, using plugins like building blocks. It's designed to be a foundation on which to build complex applications.
Plugin Management
Base allows you to easily manage and use plugins, enabling modular application development. Plugins can add specific functionalities to the base application, which can be initialized and used as needed.
const Base = require('base');
const app = new Base();
app.use(require('some-plugin'));
app.init();
Event Handling
Base provides an event handling system. You can define custom events and handlers, making it easy to manage events within your application.
const Base = require('base');
const app = new Base();
app.on('event', () => console.log('Event triggered!'));
app.emit('event');
Task Execution
Base supports defining and running tasks. This feature allows you to organize code into tasks that can be executed on demand, simplifying complex operations into manageable units.
const Base = require('base');
const app = new Base();
app.task('do something', () => console.log('Task done!'));
app.run('do something');
Express is a web application framework for Node.js, designed for building web applications and APIs. It differs from Base in that it's specifically tailored for HTTP server functionality, whereas Base is more generalized and plugin-oriented.
Hapi is another Node.js framework for building applications and services. Hapi is similar to Base in that it supports plugins, but it is more focused on server-side applications and provides a robust configuration-led approach, compared to Base's flexible plugin system.
base is the foundation for creating modular, unit testable and highly pluggable node.js applications, starting with a handful of common methods, like
set
,get
,del
anduse
.
(TOC generated by verb using markdown-toc)
Install with npm:
$ npm i base --save
var base = require('base');
inherit
function App() {
base.call(this);
}
base.extend(App);
var app = new App();
app.set('a', 'b');
app.get('a');
//=> 'b';
instantiate
var app = base();
app.set('foo', 'bar');
console.log(app.foo);
//=> 'bar'
Inherit or instantiate with a namespace
A .namespace()
method is exposed on the exported function to allow you to create a custom namespace for setting/getting on the instance.
var Base = require('base')
var base = Base.namespace('cache');
var app = base();
app.set('foo', 'bar');
console.log(app.cache.foo);
//=> 'bar'
Create an instance of Base
with options
.
Params
options
{Object}Example
var app = new Base();
app.set('foo', 'bar');
console.log(app.get('foo'));
//=> 'bar'
Set the given name
on app._name
and app.is*
properties. Used for doing lookups in plugins.
Params
name
{String}returns
{Boolean}Example
app.is('foo');
console.log(app._name);
//=> 'foo'
console.log(app.isFoo);
//=> true
app.is('bar');
console.log(app.isFoo);
//=> true
console.log(app.isBar);
//=> true
console.log(app._name);
//=> 'bar'
Returns true if a plugin has already been registered on an instance.
Plugin implementors are encouraged to use this first thing in a plugin to prevent the plugin from being called more than once on the same instance.
Params
name
{String}: The plugin name.returns
{Boolean}: Returns true when a plugin is already registered.Events
emits
: plugin
with registered
and the name of the plugin as arguments.Example
var base = new Base();
base.use(function(app) {
if (app.isRegistered('myPlugin')) return;
// do stuff to `app`
});
Define a plugin function to be called immediately upon init. Plugins are chainable and the only parameter exposed to the plugin is the application instance.
Params
fn
{Function}: plugin function to callreturns
{Object}: Returns the item instance for chaining.Events
emits
: use
with no arguments.Example
var app = new Base()
.use(foo)
.use(bar)
.use(baz)
Lazily invoke a registered plugin. This can only be used with:
app
Params
prop
{String}: The name of the property or method added by the plugin.fn
{Function}: The plugin functionoptions
{Object}: Options to use when the plugin is invoked.returns
{Object}: Returns the instance for chainingExample
app.lazy('store', require('base-store'));
Assign value
to key
. Also emits set
with the key and value.
Params
key
{String}value
{any}returns
{Object}: Returns the instance for chaining.Events
emits
: set
with key
and value
as arguments.Example
app.on('set', function(key, val) {
// do something when `set` is emitted
});
app.set(key, value);
// also takes an object or array
app.set({name: 'Halle'});
app.set([{foo: 'bar'}, {baz: 'quux'}]);
console.log(app);
//=> {name: 'Halle', foo: 'bar', baz: 'quux'}
Return the stored value of key
. Dot notation may be used to get [nested property values][get-value].
Params
key
{String}: The name of the property to get. Dot-notation may be used.returns
{any}: Returns the value of key
Events
emits
: get
with key
and value
as arguments.Example
app.set('a.b.c', 'd');
app.get('a.b');
//=> {c: 'd'}
app.get(['a', 'b']);
//=> {c: 'd'}
Return true if app has a stored value for key
, false only if typeof
value is undefined
.
Params
key
{String}returns
{Boolean}Events
emits
: has
with key
and true or false as arguments.Example
app.set('foo', 'bar');
app.has('foo');
//=> true
Delete key
from the instance. Also emits del
with the key of the deleted item.
Params
key
{String}returns
{Object}: Returns the instance for chaining.Events
emits
: del
with the key
as the only argument.Example
app.del(); // delete all
// or
app.del('foo');
// or
app.del(['foo', 'bar']);
Define a non-enumerable property on the instance. Dot-notation is not supported with define
.
Params
key
{String}: The name of the property to define.value
{any}returns
{Object}: Returns the instance for chaining.Events
emits
: define
with key
and value
as arguments.Example
// arbitrary `render` function using lodash `template`
define('render', function(str, locals) {
return _.template(str)(locals);
});
Visit method
over the items in the given object, or map
visit over the objects in an array.
Params
method
{String}val
{Object|Array}returns
{Object}: Returns the instance for chaining.Mix property key
onto the Base prototype. If base-methods
is inherited using Base.extend
this method will be overridden
by a new mixin
method that will only add properties to the
prototype of the inheriting application.
Params
key
{String}val
{Object|Array}returns
{Object}: Returns the instance for chaining.Static method for adding global plugin functions that will be added to an instance when created.
Params
fn
{Function}: Plugin function to use on each instance.Example
Base.use(function(app) {
app.foo = 'bar';
});
var app = new Base();
console.log(app.foo);
//=> 'bar'
Static method for inheriting both the prototype and
static methods of the Base
class. See [class-utils][]
for more details.
Static method for adding mixins to the prototype. When a function is returned from the mixin plugin, it will be added to an array so it can be used on inheriting classes via Base.mixins(Child)
.
Params
fn
{Function}: Function to callExample
Base.mixin(function fn(proto) {
proto.foo = function(msg) {
return 'foo ' + msg;
};
return fn;
});
Static method for running currently saved global mixin functions against a child constructor.
Params
Child
{Function}: Constructor function of a child classExample
Base.extend(Child);
Base.mixins(Child);
Similar to util.inherit
, but copies all static properties,
prototype properties, and descriptors from Provider
to Receiver
.
[class-utils][] for more details.
Statements : 100% (88/88)
Branches : 100% (32/32)
Functions : 100% (19/19)
Lines : 100% (87/87)
There are a number of different plugins available for extending base. Let us know if you create your own!
config
method for mapping declarative configuration values to other 'base'… more | homepagedata
method to base-methods. | homepageoption
, enable
and disable
. See the readme… more | homepageInstall dev dependencies:
$ npm i -d && npm test
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Jon Schlinkert
Copyright © 2016 Jon Schlinkert Released under the MIT license.
This file was generated by verb on January 25, 2016.
FAQs
Framework for rapidly creating high quality, server-side node.js applications, using plugins like building blocks
The npm package base receives a total of 11,237,742 weekly downloads. As such, base popularity was classified as popular.
We found that base demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.